package com.qianyu.controller.back;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianyu.anno.OperLogAnnotation;
import com.qianyu.entity.base.BaseIdDto;
import com.qianyu.entity.base.Result;
import com.qianyu.entity.bean.Qun;
import com.qianyu.entity.dto.QunDto;
import com.qianyu.enumerate.OperLogEnum;
import com.qianyu.service.QunService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "后台群管理", description = "wangzhicheng")
@RestController
@RequestMapping("/back/qq_qun")
@RequiredArgsConstructor
public class QunController {

    private final QunService qunService;

    /**
     * 建群
     *
     * @param dto
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "建群")
    @OperLogAnnotation(menuName = "群管理", opeType = OperLogEnum.INSERT)
    Result<String> saveQun(@RequestBody @Validated QunDto.QunSaveDto dto) {
        return qunService.saveQun(dto) ? Result.success() : Result.error();
    }

    /**
     * 分页查询群
     *
     * @param dto
     * @return
     */
    @PostMapping("/pageList")
    @ApiOperation(value = "分页查询群")
    Result<Page<Qun>> pageList(@RequestBody @Validated QunDto.QunPageDto dto) {
        return Result.success(qunService.pageList(dto));
    }

    /**
     * 获取群详情
     */
    @PostMapping("/getInfo")
    @ApiOperation(value = "获取群详情")
    Result<Qun> getInfo(@RequestBody @Validated BaseIdDto dto) {
        return Result.success(qunService.getInfo(dto));
    }
}
